package cn.doourbest.initializer;

import cn.doourbest.config.MainSpringConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.*;


public class MainSpringApplicationInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {

        AnnotationConfigWebApplicationContext aa =
                new AnnotationConfigWebApplicationContext();
        aa.register(MainSpringConfig.class);

        DispatcherServlet dispatcherServlet = new DispatcherServlet(aa);
        dispatcherServlet.setEnableLoggingRequestDetails(true);
        ServletRegistration.Dynamic ds = servletContext.addServlet("dispatcherServlet",dispatcherServlet);
        ds.addMapping("/*");
        ds.setLoadOnStartup(1);
    }
}

